package com.gkoudai.open.platform.entry;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.Setter;

import java.io.Serializable;

/**
 * @author : Amater
 * @date : 2024/7/23 11:02
 */
@Getter
@Setter
public class ResponseBody<T>  implements Serializable {
    private String msg;
    private T data;
    private Integer status;
    private String desc;

    private ResponseBody() {
    }

    public static <T> ResponseBody<T> success() {
        return success((T) null);
    }

    public static <T> ResponseBody<T> success(T data) {
        return create(data, ResponseEnum.SUCCESS);
    }

    public static <T> ResponseBody<T> create(ResponseEnum responseEnum) {
        return create((T) null, responseEnum);
    }

    public static <T> ResponseBody<T> create(T data, ResponseEnum responseEnum) {
        return create(data, responseEnum.getMsg(), responseEnum.getStatus());
    }

    public static <T> ResponseBody<T> create(T data, String msg, Integer status) {
        ResponseBody<T> responseBody = new ResponseBody<>();
        responseBody.setMsg(msg);
        responseBody.setData(data);
        responseBody.setStatus(status);
        return responseBody;
    }

    public static <T> ResponseBody<T> create() {
        ResponseBody<T> responseBody = new ResponseBody<>();
        return responseBody;
    }

    @Getter
    @AllArgsConstructor
    public enum ResponseEnum {
        DATA_ALREADY_EXIST("data already exist", 1005, "数据已存在"),
        DATA_NOT_EXIST("data not exist", 1004, "数据不存在"),
        NO_AUTHORITY("limits of authority", 1003, "鉴权失败"),
        PARAMETER_ERROR("parameter error", 1002, "参数错误"),
        SUCCESS("success", 1000, "响应成功"),
        ERROR("error", 1001, "服务异常");
        private final String msg;
        private final Integer status;
        private final String desc;
    }
}
